package com.sumainfor.pc.gmio.service.impl;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.gmio.dao.ButlerTableMapper;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcEpcFeign;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.gmio.service.ButlerTableService;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 服务管家工作台
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-06-05 17:27
 **/
@Service
public class ButlerTableServiceImpl implements ButlerTableService {

    @Autowired
    ButlerTableMapper butlerTableMapper;

    @Autowired
    ZpcEpcFeign zpcEpcFeign;

    @Autowired
    ZpcMktFeign zpcMktFeign;

    /**
     * <p>
     * 重要消息提醒
     * </p>
     *
     * @author: zhoucong
     * @since:
     */

    //getQuarantinedRoomCount//房源待验收
    @Override
    public JsonResult getImport(Map<String, Object> params) {
        JsonResult result = new JsonResult();
        Map<String, Object> map = new HashMap<>();
        //待验收
        JsonResult zpcEpcResult = zpcEpcFeign.getQuarantinedRoomCount(params);
        Map<String, Object> zpcEpcMap = (Map<String, Object>) zpcEpcResult.get("result");
        map.putAll(zpcEpcMap);
        //维修工单跟踪

        JsonResult zpcEpcResultOne = zpcEpcFeign.getRepairTracking(params);
        Map<String, Object> zpcEpcMapOne = (Map<String, Object>) zpcEpcResultOne.get("result");
        map.putAll(zpcEpcMapOne);
        //今日退房验收
        Map<String, Object> getCheckAcceptance = butlerTableMapper.getCheckAcceptance();
        Integer cout = MapUtils.getInteger(getCheckAcceptance, "getWithdrawalCount")
                + MapUtils.getInteger(getCheckAcceptance, "getDeferred")
                + MapUtils.getInteger(getCheckAcceptance, "getForce");
        map.put("cout", cout);
        //账单延期退
        Integer getdeferredApplyCount = butlerTableMapper.getdeferredApplyCount();
        map.put("getdeferredApplyCount", getdeferredApplyCount);
        return result.put(map);
    }

    /**
     * <p>
     * 特殊事项
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @Override
    public JsonResult specialConsiderations(Map<String, Object> params) {

        //房源配置变化
        JsonResult result = new JsonResult();
        Map<String, Object> map = new HashMap<>();
        JsonResult zpcMktResult = zpcMktFeign.getHouConPactListCount();
        Map<String, Object> zpcMktMap = (Map<String, Object>) zpcMktResult.get("result");
        map.putAll(zpcMktMap);

        //超过72小时未维修
        System.out.println("接受的参数" + params);
        JsonResult zpcEpcResult = zpcEpcFeign.getNoRepairOrderCount(params);
        Map<String, Object> zpcEpcMap = (Map<String, Object>) zpcEpcResult.get("result");
        map.putAll(zpcEpcMap);

        //zc修改
        //租赁备案申请（未调）
        Integer getzulinshenqing = butlerTableMapper.getzulinshenqing();
        map.put("getzulinshenqing", getzulinshenqing);

        //训房异常回访
        JsonResult zpcMktResultOne = zpcMktFeign.getRoundsAbnormalCount();
        Map<String, Object> zpcMktOneMap = (Map<String, Object>) zpcMktResultOne.get("result");
        map.putAll(zpcMktOneMap);
        //智能设备异常
        Integer getZhiNengCount = butlerTableMapper.getZhiNengCount();
        map.put("getZhiNengCount", getZhiNengCount);

        return result.put(map);
    }
}
